package com.paomi.client.activity.detail.adapter;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.paomi.client.MyApplication;
import com.paomi.client.R;

/**
 * Created by pc on 2018/12/6
 * Describe:RecyclerView的时间轴设置
 * 给评论列表添加时间轴
 * com.paomi.client.activity.detail.adapter
 */
public class RVItemDecoration extends RecyclerView.ItemDecoration {
    private Paint mPaint;

    public RVItemDecoration(Context context) {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStrokeWidth(dip2px(MyApplication.getAppContext(), 3)); //时间轴线的宽度。
        mPaint.setColor(context.getResources().getColor(R.color.line_ea)); //时间轴线的颜色。
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDraw(c, parent, state);

        int childCount = parent.getChildCount();

        for (int i = 0; i < childCount; i++) {
            View view = parent.getChildAt(i);

            //int index = parent.getChildAdapterPosition(view);

//            float left = dip2px(MyApplication.getAppContext(), 14 + 10);
            float left = dip2px(MyApplication.getAppContext(), 2);
            float bottom = view.getBottom();

//            c.drawLine(left, dip2px(MyApplication.getAppContext(), (50 - 20) / 2), left, bottom, mPaint);
            c.drawLine(left, dip2px(MyApplication.getAppContext(), 2), left, bottom, mPaint);
        }
    }
    public static int dip2px(Context context, float dpValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
